package controller

import (
	"github.com/gofiber/fiber/v2"
	"guns-excel/internal/app/model"
	"guns-excel/internal/app/service"
	"guns-excel/internal/pkg/util/result"
)

// 新增
func AddTimedTask(ctx *fiber.Ctx) error {
	p := new(model.TimedTask)
	if err := ctx.BodyParser(p); err != nil {
		return ctx.JSON(result.Err.WithMsg("解析参数出错，请检查传参"))
	}
	if err := service.AddTimedTask(ctx, p); err != nil {
		return ctx.JSON(result.Err.WithMsg("新增失败"))
	}
	return ctx.JSON(result.OK)
}

func GetTimedTaskPage(ctx *fiber.Ctx) error {
	pager, err := result.ParsePager(ctx)
	if err != nil {
		ctx.JSON(result.Err.WithMsg("解析请求参数错误"))
	}
	m := new(model.TimedTask)
	rule, err := service.TimedTaskPageList(ctx, pager, m)
	if err != nil {
		return err
	}
	return ctx.JSON(result.OK.WithData(rule))
}
